package com.wkh.datastructure.ReverseLinkedList;

/*import javax.xml.transform.Result;
import java.util.LinkedList;*/

//反转链表----方法一
public class demo1 {
    /*public static void main(String[] args) {
        LinkedList<Integer> list = new LinkedList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        System.out.println(list);
        LinkedList<Integer> reverse = reverse(list);
        System.out.println(reverse);
    }

    private static LinkedList<Integer> reverse(LinkedList<Integer> list) {
        LinkedList<Integer> newList = new LinkedList<>();
        for (Integer element : list) {
            newList.addFirst(element);
        }
        return newList;
    }*/
    public static void main(String[] args) {
        ListNode node4 = new ListNode(null, 4);
        ListNode node3 = new ListNode(node4, 3);
        ListNode node2 = new ListNode(node3, 2);
        ListNode node1= new ListNode(node2, 1);
        ListNode reverse = reverse(node1);
    }

    private static ListNode reverse(ListNode node1) {
        ListNode head = null;
        ListNode p = node1;
        while (p != null){
            head = new ListNode(head,p.value);
            p = p.next;
        }
        return head;
    }
}
